//
//  ViewController.m
//  SD异步下载网络图片
//
//  Created by WangBiao on 16/9/17.
//  Copyright © 2016年 lsrain. All rights reserved.
//

#import "ViewController.h"
#import "AFNetworking.h"
#import "NSObject+YYModel.h"
#import "appModel.h"
#import "AppCell.h"

@interface ViewController ()

@property (nonatomic, strong)NSArray *appList;
@end


static NSString *cellID = @"cellID";
@implementation ViewController

//需求：实现异步加载网络图片
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self loadJSONData];
}

- (void)loadJSONData{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager GET:@"https://raw.githubusercontent.com/wangbiaoWB/netWork/master/apps.json" parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, NSArray *responseObject) {
       
        self.appList = [NSArray yy_modelArrayWithClass:[appModel class] json:responseObject];
        
        [self.tableView reloadData];
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@", error);
    }];
}

#pragma mark - 数据源方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.appList.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    AppCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
    
    cell.app = self.appList[indexPath.row];
    
    cell.selectionStyle = UICollectionViewScrollPositionNone;
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
